﻿/*********************************************
 创建者：  dmhai
 创建时间：2017-03-30
 功能说明：商品层参数浮动值管理
 ********************************************/
using com.nm.ApiServer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;
using com.nm.ApiServer.Attributes;
using com.nm.Attributes;
using com.nm.Helper;
using com.nm.library.Helper;
using george.Data;
using george.Helper;
using PlanAPI.model;
using NHibernateVertica;
using Vertica.Data.VerticaClient;

namespace PlanAPI
{
    [Description("商品层参数浮动值管理")]
    public class PLBasMatPFloatHandler : BaseHandler
    {
        public VerticaDataHelper Helper { get; set; } = new VerticaDataHelper();

        /// <summary>
        /// 获取区-店浮动值列表
        /// </summary>
        /// <returns></returns>
        public List<PLBasMatPFloatModel.AreaShop> GetAreaShopFloatList()
        {
            var sql = $" select MaterialProperty,AreaShopFloat from goods.goods_PL_Bas_MatPFloat ";

            //先读取缓存的值，没有再访问数据库
            var obj = HttpRuntime.Cache.Get(sql);
            if (obj != null)
            {
                return (List<PLBasMatPFloatModel.AreaShop>)obj;
            }

            VerticaCommand command = new VerticaCommand(sql);
            DataTable dt = Helper.ExecuteDataTable(command);

            var list = ModelConvertHelper<PLBasMatPFloatModel.AreaShop>.ConvertToModel(dt).ToList();
            if (list != null && list.Count > 0)
            {
                HttpRuntime.Cache.Insert(sql, list, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero, CacheItemPriority.High, null);
            }
            return list;
        }

        /// <summary>
        /// 获取月-周浮动值列表
        /// </summary>
        /// <returns></returns>
        public List<PLBasMatPFloatModel.MonthWeek> GetMonthWeekFloatList()
        {
            var sql = $" select MaterialProperty,MonthWeekFloat from goods.goods_PL_Bas_MatPFloat ";

            //先读取缓存的值，没有再访问数据库
            var obj = HttpRuntime.Cache.Get(sql);
            if (obj != null)
            {
                return (List<PLBasMatPFloatModel.MonthWeek>)obj;
            }

            VerticaCommand command = new VerticaCommand(sql);
            DataTable dt = Helper.ExecuteDataTable(command);
            var list = ModelConvertHelper<PLBasMatPFloatModel.MonthWeek>.ConvertToModel(dt).ToList();
            if (list != null && list.Count > 0)
            {
                HttpRuntime.Cache.Insert(sql, list, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero, CacheItemPriority.High, null);
            }
            return list;
        }
    }

}
